package com.onpositive.notes.parser;

import java.io.Serializable;

import com.onpositive.notes.model.ITemplateModel;
import com.onpositive.notes.services.TemplateModelRegistry;

public class TemplateOccurence implements Serializable {

	private static final long serialVersionUID = -4465158605859354800L;


	public TemplateOccurence() {
		super();
	}

	public TemplateOccurence(ITemplateModel<?> model) {
		super();
		this.modelId = model.getId() ;
	}
	
	private String modelId ;

	
	public ITemplateModel<?> getModel() {
		return TemplateModelRegistry.getInstance().getModelById(modelId) ;
	}
	
	public String toString(){
		return "Template: "+ modelId!= null ? modelId : "NULL" ;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((modelId == null) ? 0 : modelId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TemplateOccurence other = (TemplateOccurence) obj;
		if (modelId == null) {
			if (other.modelId != null)
				return false;
		} else if (!modelId.equals(other.modelId))
			return false;
		return true;
	}	
}
